package solitaire.controle;

import java.awt.datatransfer.DataFlavor;

import solitaire.InterfacesControle.ICCarte;
import solitaire.InterfacesControle.ICTas;
import solitaire.InterfacesControle.ICTasDeCartes;
import solitaire.InterfacesControle.ICTasDeCartesColorees;
import solitaire.InterfacesPresentation.IPTasDeCartesColorees;
import solitaire.application.Carte;
import solitaire.application.TasDeCartesColorees;
import solitaire.application.Usine;
import solitaire.presentation.PTasDeCartesColorees;

public class CTasDeCartesColorees extends TasDeCartesColorees implements ICTasDeCartesColorees {
	private IPTasDeCartesColorees presentation;
	
	public CTasDeCartesColorees(String nom, int couleur, Usine usine) {
		super(nom, couleur, usine);
		presentation=new PTasDeCartesColorees(this);
	}
	
	@Override
	public void depiler() {
		try {
			super.depiler();
			presentation.depiler();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	
	@Override
	public TasDeCartesColorees getAbstraction() {
		return this;
	}

	@Override
	public IPTasDeCartesColorees getPresentation() {
		return presentation;
	}

	@Override
	public void depilerICCarte() {
		try {
			super.depiler();
		} catch (Exception e) {
			e.printStackTrace();
		}
		presentation.depiler();
		
	}

	@Override
	public void empiler(Carte cartet) {
		ICCarte carte=(ICCarte) cartet;
		super.empiler(carte.getAbstraction());
		presentation.empiler(carte.getPresentation());
		
	}

	@Override
	public ICCarte getICCarteBase() {
		ICCarte carte=null;
		try {
			carte=(ICCarte) super.getBase();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return carte;
	}

	@Override
	public ICCarte getICCarte(int n) {
		ICCarte carte=null;
		try {
			carte=(ICCarte) super.getCarte(n);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return carte;
	}

	@Override
	public ICCarte getICCarteSommet() {
		ICCarte carte=null;
		try {
			carte=(ICCarte) super.getSommet();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return carte;
	}

	@Override
	public boolean isEmpilable(ICCarte carte) {
		return super.isEmpilable(carte.getAbstraction());
	}

	@Override
	public boolean isEmpilable(ICTas tas) {
		return super.isEmpilable(tas.getAbstraction());
	}

	@Override
	public boolean isEmpilable(ICTas tas, int n) {
		return super.isEmpilable(tas.getAbstraction(), n);
	}

	@Override
	public void recopier(ICTas tas) {
		super.recopier(tas.getAbstraction());
		//presentation.viderTas();
		//presentation.empiler(tas.getPresentation());
		
	}

	@Override
	public ICTas copy() {
		return this.copy();
	}

	@Override
	public boolean isEmpilable(ICTasDeCartes tas) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean isEmpilable(ICTasDeCartes tas, int nb) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public Object getTransferData(DataFlavor flavor){
		Object result=null;
		if(flavor.isMimeTypeEqual(DataFlavor.javaJVMLocalObjectMimeType)){
			result=this;
		}
		return result;
	}

	@Override
	public DataFlavor[] getTransferDataFlavors() {
		DataFlavor data[] = new DataFlavor[1];
		try{
			data[0] = new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType);
		} catch (java.lang.ClassNotFoundException e){}
		return(data);
	}

	@Override
	public boolean isDataFlavorSupported(DataFlavor flavor) {
		boolean result=false;
		if(flavor.isMimeTypeEqual(DataFlavor.javaJVMLocalObjectMimeType)){
			result=true;
		}
		return result;
	}

	@Override
	public void empiler(ICTas tas) {
		super.empiler(tas.getAbstraction());
	}

}
